var vote= new Vue({
    el : '#Votelist',
    data:{
        userId : $("#id").val(),
        userId : $("#id").val(),
        xiangmuId:$("#xiangmuId").val(),
        xiangmu : {},
        votelist:[],
        show : false,
        total:0,
        tongyishu:0,

        issubmited:false,
        isallsubmited:false,

        pageIndex : 1,
        pageSize :100,
        pageCount : 0,
        recordCount : 0,
        inputPageIndexValue : "",
    },
    created : function() {
        var _this = this;

        $(".nav navbar-nav li").removeClass("active");
        $("#nav_biaojue").addClass("active");
        _this.findIsacticed();


    },
    methods : {

        toRefresh:function (){

            location.reload();
        },

        findIsacticed:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xiangmu/find_one', {
                xianmguid :_this.xiangmuId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.xiangmu = data;
                        _this.xiangmuId=_this.xiangmu.xiangmuid;
                        _this.xiangmuleixing=_this.xiangmu.xiangmuleixing;
                        _this.checkIsSubmited();
                        _this.checkIsAllSubmited();
                        _this.getchuangxinchanpinResultCount();

                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        checkIsSubmited:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/renyuanfenpei/checkIsSubmited', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        if(ppData.resultContent=="1"){
                            _this.issubmited=true;
                        }
                        _this.findBiaojuelist();
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        checkIsAllSubmited:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/renyuanfenpei/checkIsAllSubmited', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        if(ppData.resultContent=="1"){
                            _this.isallsubmited=true;
                        }

                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },


        findBiaojuelist:function (){
            var _this = this;
            layer.open({type:3});
            $.post("/dailiangchuangxin/findbiaojuelist",{
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                pageindex : _this.pageIndex,
                pagesize : _this.pageSize,
                rdm : Math.random()
            },function(ppData){
                layer.closeAll("loading");
                if (ppData != null){
                    if(ppData.result == "1"){
                        var data=ppData.resultContent;
                        var mmHtml = "<div class='table-head'><table class=\"table table-hover table-bordered\" style=\"overflow:hidden; margin-bottom:10px;table-layout:fixed;\" v-if=\"show\" cellspacing=\"0\" cellpadding=\"0\">\n" +
                            "   <thead > <tr>\n" +
                            "       <th  style=\"text-align:center;vertical-align:middle;width:150px;\" >带量批次</th>\n" +
                            "       <th  style=\"text-align:center;vertical-align:middle;width:100px;\">序号</th>\n" +
                            "       <th  style=\"text-align:center;vertical-align:middle;width:200px;\" >产品分类</th>\n" +
                            "       <th  style=\"text-align:center;vertical-align:middle;width:100px;\" >中标编码</th>\n" +
                            "       <th  style=\"text-align:center;vertical-align:middle;width:200px;\" >产品名称</th>\n" +
                            "       <th  style=\"text-align:center;vertical-align:middle;width:100px;\" >产品规格</th>\n" +
                            "       <th  style=\"text-align:center;vertical-align:middle;width:100px;\" >产品型号</th>\n" +
                            "       <th  style=\"text-align:center;vertical-align:middle;width:150px;\" >注册证号</th>\n" +
                            "       <th  style=\"text-align:center;vertical-align:middle;width:150px;\" >生产厂家</th>\n" +
                            "       <th  style=\"text-align:center;vertical-align:middle;width:100px;\" >单位</th>\n" +
                            "       <th  style=\"text-align:center;vertical-align:middle;width:100px;\" >单价/元</th>\n" +
                            "       <th  style=\"text-align:center;vertical-align:middle;\" >表决意见（同意请打勾）</th>\n" +
                            "   </tr>" +
                            "   </thead></table></div><div class='table-body'><table style=\"table-layout: fixed;\"><tbody>";
                        if(data.Biaojuelist.length>0){
                            _this.show = true;
                            var PageInfo = data.PageInfo;
                            _this.pageIndex = PageInfo.pageIndex;
                            _this.recordCount = PageInfo.recordCount;
                            _this.pageCount = PageInfo.pageCount;

                            for (var i = 0; i < data.Biaojuelist.length; i++) {
                                var mmChuangxinOne = data.Biaojuelist[i];
                                var mmResult=mmChuangxinOne.result;
                                var mmId=mmChuangxinOne.id;

                                var mmpaixuhao = mmChuangxinOne.ordernumber;
                                var mmdailiangpici = mmChuangxinOne.dailiangpici;
                                var mmchanpinfenlei = mmChuangxinOne.chanpinfenlei;
                                var mmzhongbiaobianma = mmChuangxinOne.zhongbiaobianma;
                                var mmchanpinmingcheng = mmChuangxinOne.chanpinmingcheng;
                                var mmchanpinguige = mmChuangxinOne.chanpinguige;
                                var mmchanpinxinghao = mmChuangxinOne.chanpinxinghao;
                                var mmzhecezhenghao = mmChuangxinOne.zhecezhenghao;
                                var mmshengchanchangjia = mmChuangxinOne.shengchanchangjia;
                                var mmdanwei = mmChuangxinOne.danwei;
                                var mmdanjia = mmChuangxinOne.danjia;

                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:150px;'>" + mmdailiangpici + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmpaixuhao + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:200px;'>" + mmchanpinfenlei + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmzhongbiaobianma + "'>" + mmzhongbiaobianma + "</a></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:200px;'>" + mmchanpinmingcheng + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmchanpinguige + "'>" + mmchanpinguige + "</a></td>"
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a title='" + mmchanpinxinghao + "'>" + mmchanpinxinghao + "</a></td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:150px;'>" + mmzhecezhenghao + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:150px;'>" + mmshengchanchangjia + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmdanwei + "</td>";
                                mmHtml += "<td style='text-align:center;vertical-align:middle;width:100px;'>" + mmdanjia + "</td>";

                                var mmBtndiv="";
                                if(_this.issubmited){
                                    if(mmResult==null||mmResult==0){
                                        mmBtndiv="<div style=\"text-align:center;\"><input style=\"height:20px;width: 20px;\" disabled onclick=\"toVote('"+mmId+"')\" class='cbcss' id='checkbox_"+mmId+"' type=\"checkbox\"></div>";
                                    }
                                    if(mmResult==1){
                                        mmBtndiv="<div style=\"text-align:center;\"><input style=\"height:20px;width: 20px;\" disabled checked onclick=\"toVote('"+mmId+"')\" class='cbcss' id='checkbox_"+mmId+"' type=\"checkbox\"></div>";
                                    }
                                }
                                if(!_this.issubmited) {
                                    if(mmResult==null||mmResult==0){
                                        mmBtndiv="<div style=\"text-align:center;\"><input style=\"height:20px;width: 20px;\"  onclick=\"toVote('"+mmId+"')\" class='cbcss' id='checkbox_"+mmId+"' type=\"checkbox\"></div>";
                                    }
                                    if(mmResult==1){
                                        mmBtndiv="<div style=\"text-align:center;\"><input style=\"height:20px;width: 20px;\" checked  onclick=\"toVote('"+mmId+"')\" class='cbcss' id='checkbox_"+mmId+"' type=\"checkbox\"></div>";
                                    }
                                }
                                mmHtml +="<td style='text-align:center;vertical-align:middle;height: 100%'>" + mmBtndiv + "</td>";

                                mmHtml += "</tr>";

                            }
                        }else {
                            _this.show = false;
                        }
                        mmHtml += "</table>";
                        $("#List").html(mmHtml);
                    }else{
                        layer.alert(ppData.message);
                    }
                }

            },"json");
        },

        getchuangxinchanpinResultCount:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/jieguo/getChuangxinchanpinResultCount', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.tongyishu=data.tongyiShu;
                        _this.total=data.total;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },
        toVoteAll:function (){
            var _this = this;
            layer.confirm("确定全部同意当前表决项？",{
                btn : ['是','否']
            },function(){
                layer.open({type:3});
                $.post("/jieguo/toupiao_all", {
                    xiangmuid :_this.xiangmuId,
                    userid :_this.userId,
                    random : Math.random()
                }, function(ppData) {
                    if (ppData != null) {
                        layer.closeAll("loading");
                        if(ppData.result != "1"){
                            layer.alert(ppData.message);
                        }else{
                            layer.open({
                                time:1000,
                                btn:[],
                                content:"操作成功!",
                            });
                            window.location.reload();
                        }
                    }
                },"json");
            })
        },

        tosubmit:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/renyuanfenpei/submit', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        _this.issubmited=true;
                        layer.alert("提交成功");
                        _this.findBiaojuelist();
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },


        /**
         * 合并单元格(如果结束行传0代表合并所有行)
         * @param table1    表格的ID
         * @param startRow  起始行
         * @param endRow    结束行
         * @param col   合并的列号，对第几列进行合并(从0开始)。第一行从0开始
         */
        /* mergeCell: function (tableId, startRow, endRow, col) {
             alert(startRow)
             var tb = document.getElementById(tableId);
             if (col >= tb.rows[0].cells.length) {
                 return;
             }
             if (col == 0) { endRow = tb.rows.length-1; }
             for (var i = startRow; i < endRow; i++) {
                 if (tb.rows[startRow].cells[col].innerHTML == tb.rows[i + 1].cells[0].innerHTML) {
                     tb.rows[i + 1].removeChild(tb.rows[i + 1].cells[0]);
                     tb.rows[startRow].cells[col].rowSpan = (tb.rows[startRow].cells[col].rowSpan | 0) + 1;
                     if (i == endRow - 1 && startRow != endRow) {
                         mc(tableId, startRow, endRow, col + 1);
                     }
                 } else {
                     this.mergeCell(tableId, startRow, i + 0, col + 1);
                     startRow = i + 1;
                 }
             }
          },*/

        //跳到首页
        SetPageIndex : function(){
            this.pageIndex = 1;
        },
        SetPageEnd : function(){
            this.pageIndex = this.pageCount;
        },
        //上一页
        SetPageIndexPrePage : function(){
            var PrePage = ((this.pageIndex -1) <= 0) ? 1 : (this.pageIndex -1);
            this.pageIndex = PrePage;
        },
        //下一页
        SetPageIndexNextPage : function(){
            var NextPage = ((this.pageIndex +1) >= this.pageCount) ? this.pageCount : (this.pageIndex +1);
            this.pageIndex = NextPage;
        },
        //跳转界面
        JumpPage : function(){
            if(this.inputPageIndexValue <= 1){
                this.inputPageIndexValue = 1;
            }else if(this.inputPageIndexValue >= this.pageCount){
                this.inputPageIndexValue = this.pageCount;
            }
            this.pageIndex = this.inputPageIndexValue;
            this.inputPageIndexValue = '';
        },
    },
    watch :{
        //监控分页情况，刷新列表
        pageIndex : function(){

            this.findBiaojuelist();
        }
    }
})